package com.click.app.model;


import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author Joel Chuca Condo
 * @date 15/06/2009
 */ 
@Entity
@Table(name="pant_designs")
public class PantDesign extends BaseObject {
    private static final long serialVersionUID = 1L;
    
    private Long id;
    private Material material;
    private Model model;
    private ModelSize modelSize;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_pant_design")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="id_material")
    public Material getMaterial() {
        return material;
    }

    public void setMaterial(Material material) {
        this.material = material;
    }

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="id_model")
    public Model getModel() {
        return model;
    }

    public void setModel(Model model) {
        this.model = model;
    }

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="id_model_size")
    public ModelSize getModelSize() {
        return modelSize;
    }

    public void setModelSize(ModelSize modelSize) {
        this.modelSize = modelSize;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PantDesign)) {
            System.out.println("Error 1 en la igualacion de objetos");
            return false;
        }
        PantDesign other = (PantDesign) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            System.out.println("Error 2 en la igualacion de objetos: "+this.id+" , "+other.id);
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.PantDesign[id=" + id + "]";
    }

    @Transient
    public String getDatas(){
        return model.getGender()+" - "+model.getType()+" "+
               modelSize.getValueSize()+" "+material.getName();
    }

    @Transient
    public String getDatasModelAndMaterial(){
        return model.getGender()+" - "+model.getType()+" "+material.getName();
    }

}
